home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / Appearance SDK 1.0.4 / Appearance Sample Code / Source / LiveFeedbackDialog.cp < prev    next >
Encoding:
Text File  |  1999-07-16  |  3.6 KB  |  133 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        LiveFeedbackDialog.cp
  3.  
  4.     Contains:    Demonstration of live feedback.
  5.  
  6.     Version:    Appearance 1.0 SDK
  7.  
  8.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                Edward Voas
  13.  
  14.         Other Contact:        7 of 9, Borg Collective
  15.  
  16.         Technology:            OS Technologies Group
  17.  
  18.     Writers:
  19.  
  20.         (edv)    Ed Voas
  21.  
  22.     Change History (most recent first):
  23.  
  24.          <1>     9/11/97    edv        First checked in.
  25. */
  26.  
  27. //
  28. //    This file implements a dialog demonstrating live feedback with sliders
  29. //    and scroll bars. In this case, we have one of each control. They are
  30. //    connected to a text field showing the current value as well as each
  31. //    other, i.e. moving one automatically adjusts the other.
  32. //
  33.  
  34. #include <TextUtils.h>
  35. #include "LiveFeedbackDialog.h"
  36. #include "Appearance.h"
  37. #include "AppearanceHelpers.h"
  38.  
  39. enum {
  40.     kScrollBar            = 1,
  41.     kSlider                = 2,
  42.     kStaticText            = 4
  43. };
  44.  
  45. ControlActionUPP    LiveFeedbackDialog::fProc = NewControlActionProc( LiveFeedbackDialog::LiveActionProc );
  46.  
  47. LiveFeedbackDialog::LiveFeedbackDialog() : BaseDialog( 1004 )
  48. {
  49.     if ( fWindow )
  50.     {
  51.             // These controls have been created with a live scrolling
  52.             // variant. We'll set the action proc using SetControlAction.
  53.             
  54.         GetDialogItemAsControl( fWindow, kScrollBar, &fScrollBar );
  55.         SetControlReference( fScrollBar, (long)this );
  56.         GetDialogItemAsControl( fWindow, kSlider, &fSlider );
  57.         SetControlReference( fSlider, (long)this );
  58.  
  59.         SetControlAction( fScrollBar, fProc );
  60.         SetControlAction( fSlider, fProc );
  61.     }
  62. }
  63.  
  64. LiveFeedbackDialog::~LiveFeedbackDialog()
  65. {
  66. }
  67.  
  68. //—————————————————————————————————————————————————————————————————————————————————
  69. //    • LiveActionProc
  70. //—————————————————————————————————————————————————————————————————————————————————
  71. //    Here's our ControlActionUPP that also handles the indicator. At last, we can
  72. //    actually use the same function callback for both! There is a difference when
  73. //    called with the indicator as the part, as opposed to the up/down arrows, etc.
  74. //    If we are called because the indicator is being dragged, the value has already
  75. //    been calculated for us. If we are being called because the scroll bar arrows
  76. //    have been pressed, then we must determine how much to scroll by and set the
  77. //    scroll bar value accordingly. This allows us to have control over the amount
  78. //    that arrows scroll by. We can allow the indicator dragging to determine the
  79. //    value because the indicator always shows a percentage.
  80. //
  81. pascal void
  82. LiveFeedbackDialog::LiveActionProc( ControlHandle control, SInt16 part )
  83. {
  84.     ControlHandle        text;
  85.     Str255                valueText;
  86.     LiveFeedbackDialog*    dialog;
  87.     SInt16                startValue;
  88.     SInt16                delta;
  89.     
  90.     startValue = GetControlValue( control );
  91.     
  92.     delta = 0;
  93.     
  94.     switch ( part )
  95.     {
  96.         case kControlUpButtonPart:
  97.             if ( startValue > GetControlMinimum( control ) )
  98.                 delta = -1;
  99.             break;
  100.         
  101.         case kControlDownButtonPart:
  102.             if ( startValue < GetControlMaximum( control ) )
  103.                 delta = 1;
  104.             break;
  105.         
  106.         case kControlPageUpPart:
  107.             if ( startValue > GetControlMinimum( control ) )
  108.                 delta = -10;
  109.             break;
  110.         
  111.         case kControlPageDownPart:
  112.             if ( startValue < GetControlMaximum( control ) )
  113.                 delta = 10;
  114.             break;
  115.     }
  116.     if ( delta )
  117.         SetControlValue( control, startValue + delta );
  118.  
  119.     if ( part != kControlIndicatorPart && delta == 0 )
  120.         return;
  121.  
  122.     dialog = (LiveFeedbackDialog*)GetControlReference( control );
  123.  
  124.     GetDialogItemAsControl( (**control).contrlOwner, kStaticText, &text );
  125.     NumToString( GetControlValue( control ), valueText );
  126.     SetStaticTextText( text, valueText, true );
  127.  
  128.     if ( control == dialog->fScrollBar )
  129.         SetControlValue( dialog->fSlider, GetControlValue( control ) );
  130.     else
  131.         SetControlValue( dialog->fScrollBar, GetControlValue( control ) );
  132. }
  133.